package com.bjwl.wybx.controller.safty;

import com.bjwl.wybx.VO.PayDetailVO;
import com.bjwl.wybx.VO.RepaireVO;
import com.bjwl.wybx.entity.PayDetail;
import com.bjwl.wybx.entity.Repaire;
import com.bjwl.wybx.service.RepaireService;
import com.bjwl.wybx.util.Result;
<<<<<<< HEAD
import org.apache.ibatis.annotations.Param;
=======
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/safty/repaire")
public class RepaireController {
    @Autowired
    private RepaireService repaireService;
    @GetMapping("/queryByUId")
    public Result queryRepaireByuId(String u_id){
        System.out.println("u_id:"+u_id);
        try {
            List<RepaireVO> repaireVOS = repaireService.queryByUId(u_id);
            System.out.println("123:"+repaireVOS);
            if(repaireVOS!=null){
                return Result.success("查询成功！",repaireVOS);
            }
            return Result.fail("查询为空");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败，系统升级中!");
        }
    }
<<<<<<< HEAD

=======
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
    //查询某一个报修单
    @GetMapping("/queryOne")
    public Result queryOneRepaire(Integer repaire_id){
        try {
            RepaireVO repaireVO = repaireService.queryOne(repaire_id);
            return Result.success("查询成功",repaireVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败，系统升级中!");
        }
    }
    //业主根据状态查询报修单
    @GetMapping("/queryByUIdAndRepaireStatus")
<<<<<<< HEAD
    public Result queryByUIdAndRepaireStatus(String u_id,Integer repaire_status){
=======
    public Result queryByUIdAndRepaireStatus(String u_id,String repaire_status){
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
        try {
            //调用service层方法查询相应的报修单
            List<RepaireVO> repaireVOS = repaireService.queryByUIdAndRepaireStatus(u_id,repaire_status);
            if(repaireVOS!=null){
                return Result.success("查询成功！",repaireVOS);
            }
            return Result.fail("查询为空");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败，系统升级中!");
        }
    }
    //业主添加报修单
    @PostMapping("/addRepaire")
    public Result addRepaire(@RequestBody Repaire repaire){
        try {
            //调用service层方法添加报修单
            int i = repaireService.addRepaire(repaire);
            if(i>0){
                return Result.success("添加成功！");
            }
            return Result.fail("添加失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，添加失败");
        }
    }
    //修改报修单
    @PutMapping("/updateRepaire")
    public Result updateRepaire(@RequestBody Repaire repaire){
        try {
            int i = repaireService.updateRepaire(repaire);
            if(i>0){
                return Result.success("修改成功！");
            }
            return Result.fail("修改失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，修改失败");
        }
    }
<<<<<<< HEAD
=======
    //修改某报修单状态
    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody Repaire repaire){
        try {
            int i = repaireService.updateStatus(repaire);
            if(i>0){
                return Result.success("修改成功！");
            }
            return Result.fail("修改失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，修改失败");
        }
    }
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
    //添加缴费明细
    @PostMapping("/addPayDetail")
    public Result addPayDetail(@RequestBody PayDetail payDetail){
        try {
            int i = repaireService.addPayDetail(payDetail);
            if(i>0){
                return Result.success("缴费明细添加成功");
            }
            return Result.fail("缴费明细添加失败");
        }
        catch (Exception e){
            e.printStackTrace();
            return Result.fail("系统升级中，缴费明细添加失败");
        }
    }
<<<<<<< HEAD
    //获取所有维修报单
    @GetMapping("list")
    public Result queryList(){
        try {
            List<RepaireVO> repaireVOS = repaireService.queryList();
            return Result.success("查询成功",repaireVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }

=======
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
    //查询缴费明细
    @GetMapping("queryAllPayDetail")
    public Result queryAllPayDetail(){
        try {
            List<PayDetailVO> payDetailVOList = repaireService.queryAllPayDetail();
            return Result.success("查询成功",payDetailVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }
    //更新缴费状态
    @PutMapping("/updatePayDetailStatus")
    public Result updatePayDetailStatus(@RequestBody PayDetail payDetail){
        //调用service层方法更新缴费单的状态
        try {
            int i = repaireService.updatePayDetailStatus(payDetail);
            if(i>0){
                return Result.success("更新成功");
            }
            return Result.success("更新失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.success("系统升级中，更新失败");
        }

    }
    @GetMapping("queryPayDetailByUId")
    public Result queryPayDetailByUId(String u_id){
        try {
            List<PayDetailVO> payDetailVOList = repaireService.queryAllPayDetailByUId(u_id);
            return Result.success("查询成功",payDetailVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }
    @GetMapping("queryOnePayDetail")
    public Result queryOnePayDetail(Integer payDetail_id){
        try {
            PayDetailVO payDetailVO = repaireService.queryOnePayDetail(payDetail_id);
            return Result.success("查询成功",payDetailVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }
<<<<<<< HEAD
    //修理工
    @GetMapping("/listRepaireMan")
    public Result queryListRepaireMan(){
        try {
            List<String> list = repaireService.queryListRepaireMan();
            if(list!=null){
                return Result.success("查询成功",list);
            }
            return Result.fail("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，查询失败");
        }
    }

    //添加维修员与维修单的联系
    @GetMapping("addUserRepaire")
    public Result addUserRepaire(String u_id,Integer repaire_id){
        System.out.println("uid:"+u_id+",repaire_id"+repaire_id);
        try {
            //调用service层方法添加报修单
            int i = repaireService.addUserRepaire(u_id,repaire_id);
            if(i>0){
                return Result.success("添加成功！");
            }
            return Result.fail("添加失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，添加失败");
        }
    }

    @PutMapping("updateRepaireman")
    public Result updateRepaireMan(String repaireman,Integer repaire_id){
        //调用service层方法更新缴费单的状态
        try {
            int i = repaireService.updateRepaireMan(repaireman,repaire_id);
            if(i>0){
                return Result.success("更新成功");
            }
            return Result.fail("更新失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，更新失败");
        }
    }
    //获取该维修员的订单
    @GetMapping("queryRepaireVOByUId")
    public Result queryRepaireVOByUId(String u_id){
        System.out.println(u_id);
        try {
            List<RepaireVO> list=repaireService.queryRepaireVOByUId(u_id);
            if(list!=null){
                return Result.success("查询维修员订单数据成功",list);
            }
            return Result.fail("查询失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，更新失败");
        }
    }
    //添加 维修人员并且更改维修状态
//    @PutMapping("updateRepaireStatusAndaddRepaireMan")
//    public Result UpdateRepaireStatusAndaddRepaireMan(String u_id,Integer repaire_id){
//        try {
//            int num=repaireService.updateRepaireManAndStatus(u_id,repaire_id);
//            if(num>0){
//                return Result.success("更新成功");
//            }
//            return Result.fail("更新失败");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.fail("更新失败");
//        }
//    }
    //updateRepaireStatusById
    @PutMapping("updateRepaireStatusById/{repaire_id}")
    public Result updateRepaireStatusById(@PathVariable("repaire_id") Integer repaire_id){
        System.out.println(repaire_id);
        try {
            int num=repaireService.updateRepaireStatusById(2,repaire_id);
            if(num>0){
                return Result.success("更新成功");
            }
            return Result.fail("更新失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("更新失败");
        }
    }
    //修改审核状态
    @PutMapping("passAudit/{repaire_id}")
    public Result passAudit(@PathVariable("repaire_id") Integer repaire_id){
        try {
            int num=repaireService.passAudit(repaire_id);
            if(num>0){
                return Result.success("更新成功");
            }
            return Result.fail("更新失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("系统升级中，更新失败");
        }
    }
    //修改维修完成的状态
    @PutMapping("finishRepaire/{repaire_id}")
    public Result finishRepaire(@PathVariable("repaire_id") Integer repaire_id){
        try {
            int num=repaireService.finishRepaire(repaire_id);
            if(num>0){
                return Result.success("更新成功");
            }
            return Result.fail("更新失败");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("系统升级中，更新失败");
        }
    }

    @PutMapping("UpdateCommentById/{comment}/{repaire_id}")
    public Result UpdateCommentById(@PathVariable("comment") String comment,@PathVariable("repaire_id") Integer repaire_id)
    {
        try{
            int num = repaireService.UpdateCommentById(comment,repaire_id);
            if(num > 0){
                return Result.success("评论成功");
            }else{
                return Result.fail("评论失败，请稍后再试");
            }
        }catch(Exception e){
            return Result.fail("系统更新中...");
        }
    }

=======
>>>>>>> 70f7e19d6da4b30f0412d394b1171a015e63af36
}
